package com.jb.util;

public class Meter {
    static boolean dumpStack = "TRUE".equalsIgnoreCase(System.getProperty("MeterDumpStack"));
    static boolean meterOn = "TRUE".equalsIgnoreCase(System.getProperty("MeterOn"));
    static long duration;
    static long startAt;
    private Meter()
     {
        
    }
    static public long sinceStart() {
        return System.currentTimeMillis() - startAt;
    }

    static public void start() {
        if (meterOn) {
            startAt = System.currentTimeMillis();
        }
    }
    
    static public void stop(String msg) {
        if (!meterOn) {
            return;
        }

        duration = sinceStart();
        if(duration>55)
          System.err.println(msg + " - " + duration);

        //should work on property value
        if (dumpStack || duration>1000) {
            Thread.dumpStack();
        }
    }
}
